using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using Microsoft.Xna.Framework;
using UWBGL_WinForms_Lib1;
using UWBGL_XNA_Lib10;

namespace XNA_WCSupport
{
	class DrawOnlyHandler : UWB_XNAWindowHandler
	{
		private UWBGL_UIWindow mWindow;
		private int hwX, hwY, dvX, dvY;

		public DrawOnlyHandler()
		{
			hwX = hwY = dvX = dvY = 0;
			mWindow = new UWBGL_UIWindow(true);
		}

		public override void OnMouseMove(MouseEventArgs e)
		{
			int deviceX = 0, deviceY = 0;
			hardwareToDevice(e.X, e.Y, ref deviceX, ref deviceY);

			string key = "";
			Keys modkey = Control.ModifierKeys;
			if (modkey == Keys.Control)
				key += "[CTRL]";
			if (modkey == Keys.Shift)
				key += "[SHIFT]";
			if (key.Length == 0)
				key += "[NONE]";

			string btn = "";
			switch (e.Button)
			{
				case MouseButtons.Left:
					btn = "LMB";

					break;
				case MouseButtons.Right:
					btn = "RMB";

					break;
				case MouseButtons.Middle:
					btn = "MMB";
					break;
			}

			string msg = "Small window:" + btn + ": Position: (" + deviceX.ToString() + " " + deviceY.ToString() + ") Keys: " + key;
			//UWB_Utility.echoToStatusArea(msg);

			Program.getModel().HoverLocation = "Small Window";
			Program.getModel().hardwareX = e.X;
			Program.getModel().hardwareY = e.Y;
			Program.getModel().deviceX = deviceX;
			Program.getModel().deviceY = deviceY;
			Program.getModel().computeWorldCoordinatesSmall(mWindow.Width, mWindow.Height, deviceX, deviceY); // world coordinate
		}


		public bool Initialize(Control PlaceHolder)
		{
			if (!mWindow.ReplaceFormControl(PlaceHolder.Handle))
				return false;

			if (!mWindow.AttachHandler(this))
				return false;

			return true;
		}

		public override void DrawGraphics()
		{
			
			//UWB_BoundingBox smallView;
				m_WCWindow.setCorners(
				new Vector3(Program.getModel().originWCSmallX - Program.getModel().sizeWCSmallX / 2f,
				Program.getModel().originWCSmallY - Program.getModel().sizeWCSmallY / 2f, 0f),
				new Vector3(Program.getModel().originWCSmallX + Program.getModel().sizeWCSmallX / 2f,
				Program.getModel().originWCSmallY + Program.getModel().sizeWCSmallY / 2f, 0f));
			BeginScene();

			loadW2NDCXform();

			Program.getModel().drawModel();

			EndSceneAndShow();
		}

		#region get/set for coordinates
		public int hardwareX
		{
			get
			{
				return hwX;
			}

			set
			{
				hwX = value;
			}
		}

		public int hardwareY
		{
			get
			{
				return hwY;
			}

			set
			{
				hwY = value;
			}
		}

		public int deviceX
		{
			get
			{
				return dvX;
			}

			set
			{
				dvX = value;
			}
		}

		public int deviceY
		{
			get
			{
				return dvY;
			}

			set
			{
				dvY = value;
			}
		}

		public int Width
		{
			get { return mWindow.Width; }
			set { mWindow.Width = value; }
		}
		public int Height
		{
			get { return mWindow.Height; }
			set { mWindow.Height = value; }
		}

		#endregion

	}
}
